<?php

if (!isset($_SESSION['logged']))
    print "<script language='javascript'>
        window.location.href='./?url=404';
        </script>";
else {
    $iduser = $_SESSION['id'];
    $idfile = $_GET['file'];

    $sql = "DELETE FROM `user_file` WHERE `user_id` = '$iduser' AND `file_id` = '$idfile';";
    $result = mysql_query($sql, $link);
    $sql = "SELECT * FROM `user_file` WHERE `file_id` = '$idfile';";
    $result = mysql_query($sql, $link);
    if (mysql_num_rows($result) == 0) {
        $sql = "DELETE FROM `file` WHERE `id` = '$idfile';";
        $result = mysql_query($sql, $link);
    }
    print "<script language='javascript'>
        window.location.href='./';
        </script>";
}
?>
